import("stdfaust.lib");
start_freq = hslider("start_freq[style:knob]",150,5,1000,1.0);
end_freq = hslider("end[style:knob]",40,5,1000,1.0);
//hgroup("start_end",start,end);

length = hslider("Length[style:knob]",440,5,5000,1);
dist_start = hslider("DistStart[style:knob]",0.8,0.0,100,0.1);
dist_end = hslider("DistEnd[style:knob]",0.8,0.0,100.0,0.1);
gain = hslider("Gain[style:knob]",1.0,0.1,5.0,0.05);
env_slope = hslider("Env.斜度[style:knob]",0.163,0.01,1.0,0.001);
noise = hslider("Noise[style:knob]",0.0,0.0,1.0,0.01);
click = hslider("Click[style:knob]",0.4,0.0,1.0,0.05);
freq_slope = hslider("Freq.斜度[style:knob]",0.06,0.001,1.0,0.001);

//hgroup("volume env")

// 相位累加器（状态变量）
phase = phase + freq / ma.SR : %(1.0) with {
    phase = 0;
    freq = endFreq + (startFreq - endFreq) * (1 - pow(counter / length, slope));
    counter = counter + 1 : max(length);
};
// 包络生成
envelope = pow(1 - min(counter / length, 1), env);
// 波形生成
sineWave = sin(2 * ma.PI * phase);
noiseWave = no.noise;

// 最终输出
kicker = (sineWave * (1 - noise) + noiseWave * envelope * envelope * noise) * envelope;

process = kicker;